package hang.study.uistudy;



import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.widget.Button;

/**
 * Created by Administrator on 2015/8/20.
 */
public class NaviActivity extends AppCompatActivity {


    ActionBar actionBar = null;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.navi_main);

        actionBar = getSupportActionBar();

        Button btnShowActionBar = (Button)findViewById(R.id.btnShowActionBar);
        btnShowActionBar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(actionBar != null){
                    actionBar.show();
                }else {
                    Log.d(Util.LogTag,"ShowActionBar is null");
                }
            }
        });

        Button btnHideActionBar = (Button)findViewById(R.id.btnHideActionBar);
        btnHideActionBar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(actionBar != null){
                    actionBar.hide();
                }else{
                    Log.d(Util.LogTag,"HideActionBar is null");
                }
            }
        });

        View.OnClickListener clickListener = new ButtonClickListener(this);
        Button btnRollBall = (Button)findViewById(R.id.btnRollBall);
        btnRollBall.setOnClickListener(clickListener);
        findViewById(R.id.btnFrameTest).setOnClickListener(clickListener);
        findViewById(R.id.btnImgTest).setOnClickListener(clickListener);
        findViewById(R.id.btnListTest).setOnClickListener(clickListener);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu){

        SubMenu prog = menu.addSubMenu("启动程序");

        //baiduOption.setHeaderIcon(R.drawable)
        prog.setHeaderTitle("选择你要启动的程序");
        MenuItem baidu = prog.add("百度地图");
        //设置关联的Activity
        baidu.setIntent(new Intent(this,BaiduMapActivity.class));
        return  super.onCreateOptionsMenu(menu);
    }

    private class ButtonClickListener implements View.OnClickListener{

        Context context = null;

        public ButtonClickListener(Context context){
            this.context = context;
        }

        /**
         * Called when a view has been clicked.
         *
         * @param v The view that was clicked.
         */
        @Override
        public void onClick(View v) {
            int id = v.getId();
            Class<?> cls = null;
            switch (id){
                case R.id.btnHideActionBar:
                    break;
                case R.id.btnRollBall:
                    cls = RollBallActivity.class;
                    break;
                case R.id.btnFrameTest:
                    cls = TestFrameActivity.class;
                    break;
                case R.id.btnImgTest:
                    cls = TestImgActivity.class;
                    break;
                case R.id.btnListTest:
                    cls = TestListActivity.class;
                    break;
            }
            if(cls != null){
                Intent intent = new Intent(this.context,cls);
                startActivity(intent);
            }
        }
    }

}
